import streamlit as st
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config import settings


# Database engine, which binds with db driver
@st.cache_resource
def get_sync_engine():
    return create_engine(
        url=settings.DATABASE_URL_psycopg,
        echo=False,
    )


# Session factory, which controls connection and commits
@st.cache_resource
def get_session_factory():
    return sessionmaker(bind=get_sync_engine())
